/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javatestapplication;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author ahmet
 */
public class Main extends JFrame implements Runnable{

    private JSlider js;
    private Container c;
    private Thread t;
    private JLabel jl;
    public Main() {
        super("Posture Correction Project Team - Java Test Application ");
        setSize(500, 400);
        js = new JSlider(0,100,50);
        jl = new JLabel("Change the value with slider. Current value: "+js.getValue());
        c = getContentPane();

        c.setLayout(new BorderLayout());
        c.add(js, BorderLayout.SOUTH);
        c.add(jl, BorderLayout.CENTER);

        t = new Thread(this);
        t.start();

        addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent arg0) {
                super.windowClosing(arg0);
                if (t.isAlive()) {
                    t = null;
                }
            }

        });

        js.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent arg0) {
                int value = ((JSlider)(arg0.getSource())).getValue();
                jl.setText("Change the value with slider. Current value: "+value);
            }
        });


        setVisible(true);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        new Main();
    }

    public void run() {
        while(t!=null) {
            System.out.println("counting");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }

}
